package com.fire.security.controller;

import com.fire.security.domain.Result;
import com.fire.security.service.ArticleService;
import com.fire.security.service.DeviceService;
import com.fire.security.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/workBench")
public class WorkBenchController {
    //注入redis模板
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private ArticleService articleService;

    @Autowired
    private DeviceService deviceService;

    @Autowired
    private ShopService shopService;
    //得到今日添加文章量
    @GetMapping("/getTodayArticles")
    public Result getTodayArticles(){
        return articleService.selectTodayArticles();
    }

    //得到今日浏览量
    @GetMapping("/getTodayViewer")
    public Result getTodayViewer(){
        if (!stringRedisTemplate.hasKey("todayViewer")){
            return Result.ok(0);
        }else {
            int todayViewer = Integer.parseInt(stringRedisTemplate.opsForValue().get("todayViewer"));
            return Result.ok(todayViewer);
        }
    }

    //得到今日新增商铺
    @GetMapping("/getTodayShop")
    public Result getTodayShop(){
        if (!stringRedisTemplate.hasKey("todayShop")){
            return Result.ok(0);
        }else {
            int todayShop = Integer.parseInt(stringRedisTemplate.opsForValue().get("todayShop"));
            return Result.ok(todayShop);
        }
    }

    @GetMapping("/getTodayDevice")
    public Result getTodayDevice(){
        return deviceService.selectTodayDevice();
    }

    @GetMapping("/getTodayUser")
    public Result getTodayUser(){
        if (!stringRedisTemplate.hasKey("todayUser")){
            return Result.ok(0);
        }else {
            int todayUser = Integer.parseInt(stringRedisTemplate.opsForValue().get("todayUser"));
            return Result.ok(todayUser);
        }
    }
}

